package com.cn.xact.ty_treasured_book;

import java.util.ArrayList;
import java.util.List;

public class TYApplicationModule {

    private final static String TY_APP_SEPARATOR = "_";
    private String mModuleName;
    private String mModuleDisplayName;
    private int mModuleDefaultColor;
    private boolean mIsValid = false;
    private boolean mHasChild = false;
    private boolean mIsChild = false;
    private int mChildNum = -1;
    private boolean mHaParent = false;
    private int mParentSeq = -1;
    private String mAction;
    private String mIcon = null;
    private ArrayList<TYApplicationModule> mChild = new ArrayList<TYApplicationModule>();

    public TYApplicationModule(String name, int color, boolean isChild, String action, String icon) {
        mModuleName = name;
        mModuleDefaultColor = color;
        mIsChild = isChild;
        mAction = action;
        mIcon = icon;

        String[] tmp = mModuleName.split(TY_APP_SEPARATOR);

        if (isChild) {
            mParentSeq = Integer.valueOf(tmp[0]);
            mModuleDisplayName = new String(tmp[1]);

            //Todo : Extends tmp[2] for 3 Level menus.
        } else {
            mModuleDisplayName = new String(tmp[0]);

            if (tmp.length > 1) {
                mHasChild = true;
                mChildNum = Integer.valueOf(tmp[1]);
                mParentSeq = Integer.valueOf(tmp[2]);
            }
        }
    }

    public void setEnable(boolean enabled) {
        mIsValid = enabled;
    }

    public void addChild(TYApplicationModule child) {
        mChild.add(child);
    }

    public void removeChild(TYApplicationModule child) {
        mChild.remove(child);
    }

    public boolean isEnable() {
        return mIsValid;
    }

    public boolean isChild() {
        return mIsChild;
    }

    public boolean hasChild() {
        return mHasChild;
    }

    public String getDisplayName() {
        return mModuleDisplayName;
    }

    public String getName() {
        return mModuleName;
    }

    public int getColor() {
        return mModuleDefaultColor;
    }

    public int getChildNum() {
        return mChildNum;
    }

    public int getSeq() {
        return mParentSeq;
    }

    public String getAction() {
        return mAction;
    }

    public ArrayList<TYApplicationModule> getChilds() {
        return mChild;
    }

    public String getIconId() {
        return mIcon;
    }
}
